//
//  YGConsultViewController.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/4/8.
//
#import "YGHomeBLL.h"
#import "YGConsultViewController.h"
#import "YGAttendingDoctorTableViewCell.h"
#import "YGConsultListTableViewCell.h"
#import "YGDoctorMessageModel.h"


@interface YGConsultViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) YGDoctorMessageModel *doctorModel;
@property (nonatomic, strong) NSArray *expertsModel;
@property (nonatomic, assign) NSInteger page;
@property (nonatomic, assign) NSInteger totalPage;
@property (nonatomic, assign) NSInteger expertsPage;
@property (nonatomic, assign) NSInteger expertsTotalPage;








@end

@implementation YGConsultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    [self initconstraints];
    [self requestData];
    // Do any additional setup after loading the view.
}

-(void)initView{
    [self.view addSubview:self.tableView];
    _expertsModel = [NSMutableArray array];
}

-(void)initconstraints{
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.mas_equalTo(self.view);
    }];
}

-(void)requestData{
    WeakSelf(self);
        [YGHomeBLL requestDoctorMessageWithPage:self.page rows:1 Success:^(YGDoctorMessageModel * _Nonnull model, NSInteger totalPage) {
            weakself.doctorModel = model;
            weakself.totalPage = totalPage;
            [weakself.tableView reloadData];

        } fail:^(NSError * _Nonnull error) {
            
        }];
    
        [YGHomeBLL requestExpertsListWithPage:self.expertsPage rows:1 Success:^(YGExpertsListModel * _Nonnull model, NSInteger totalPage) {
            weakself.expertsModel = model.pageData;
            weakself.expertsTotalPage = model.totalPage;
            [weakself.tableView reloadData];
        } fail:^(NSError * _Nonnull error) {
            
        }];
            

}




#pragma tableView delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.00001;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 0.000001;
    }else{
        return 10;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 270;
    }else{
        
        return 557;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        YGAttendingDoctorTableViewCell *cell = [[YGAttendingDoctorTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YGAttendingDoctorTableViewCell"];
        [cell configureDataWith:self.doctorModel];
        
        return cell;
    }else{
        YGConsultListTableViewCell *cell = [[YGConsultListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YGConsultListTableViewCell"];
        [cell configureDataWith:self.expertsModel];
        return cell;
    }
}

#pragma setter
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        [_tableView registerClass:YGAttendingDoctorTableViewCell.class forCellReuseIdentifier:@"YGAttendingDoctorTableViewCell"];
        [_tableView registerClass:YGConsultListTableViewCell.class forCellReuseIdentifier:@"YGConsultListTableViewCell"];
    }
    return _tableView;
}

- (NSInteger)page{
    if (_page == 0) {
        return 1;
    }
    return _page;
}

- (NSInteger)expertsPage{
    if (_expertsPage == 0) {
        
        return 1;
    }
    return _expertsPage;
}
         
         
         
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
